home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpdem / cancprt.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  5.0 KB  |  143 lines

  1. VERSION 2.00
  2. Begin Form PrinterACTION 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Printer ACTION"
  6.    ClientHeight    =   1965
  7.    ClientLeft      =   2550
  8.    ClientTop       =   2760
  9.    ClientWidth     =   4050
  10.    Height          =   2370
  11.    Left            =   2490
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   1965
  17.    ScaleWidth      =   4050
  18.    Top             =   2415
  19.    Width           =   4170
  20.    Begin CommandButton CancelButton 
  21.       Caption         =   "Cancel"
  22.       Height          =   375
  23.       Left            =   2280
  24.       TabIndex        =   1
  25.       Top             =   1440
  26.       Width           =   1455
  27.    End
  28.    Begin PictureBox Picture1 
  29.       BackColor       =   &H00FFFFFF&
  30.       BorderStyle     =   0  'None
  31.       Height          =   735
  32.       Left            =   120
  33.       Picture         =   CANCPRT.FRX:0000
  34.       ScaleHeight     =   735
  35.       ScaleWidth      =   615
  36.       TabIndex        =   0
  37.       Top             =   240
  38.       Width           =   615
  39.    End
  40.    Begin Label PageNumber 
  41.       ForeColor       =   &H00FF0000&
  42.       Height          =   375
  43.       Left            =   240
  44.       TabIndex        =   4
  45.       Top             =   1440
  46.       Width           =   1935
  47.    End
  48.    Begin Label DocumetName 
  49.       Alignment       =   2  'Center
  50.       FontBold        =   -1  'True
  51.       FontItalic      =   0   'False
  52.       FontName        =   "MS Sans Serif"
  53.       FontSize        =   9.75
  54.       FontStrikethru  =   0   'False
  55.       FontUnderline   =   0   'False
  56.       ForeColor       =   &H000000FF&
  57.       Height          =   375
  58.       Left            =   960
  59.       TabIndex        =   3
  60.       Top             =   840
  61.       Width           =   3015
  62.    End
  63.    Begin Label PrinterHEADER 
  64.       Alignment       =   2  'Center
  65.       BackColor       =   &H00FFFFFF&
  66.       Caption         =   "Printing in Progress"
  67.       FontBold        =   -1  'True
  68.       FontItalic      =   0   'False
  69.       FontName        =   "MS Sans Serif"
  70.       FontSize        =   12
  71.       FontStrikethru  =   0   'False
  72.       FontUnderline   =   0   'False
  73.       ForeColor       =   &H000000FF&
  74.       Height          =   615
  75.       Left            =   840
  76.       TabIndex        =   2
  77.       Top             =   120
  78.       Width           =   3135
  79.    End
  80. Sub CancelButton_Click ()
  81.     pABORT = True
  82.     Beep
  83. End Sub
  84. Sub Command1_Click ()
  85.         pABORT = True
  86. End Sub
  87. Sub Form_Load ()
  88. ' Please note this DEMO only allows printing of TEXT Documents in the
  89. ' Current default sub-directory...
  90. ' This routine will print a file to the DEFAULT printer
  91. ' Allowing the user to CANCEL the job. The routine also offers
  92. ' proper page breaks to occur in the output.
  93. Dim PrintLine As String, HeaderLine As String
  94. Dim PageSize As Integer, LineSpace As Integer, LinesPerPage As Integer
  95. Dim LineLength As Integer, CurrentLine As Integer
  96. Dim PageInfo As TextMetric
  97.     printerACTION.Show
  98.     DocumetName.Caption = UCase$(DocName)
  99.     printerACTION.Refresh
  100.     pABORT = False              ' Set ABORT flag to FALSE
  101.     screen.mousepointer = NORMAL
  102.     code = GetTextMetrics(Printer.hdc, PageInfo) ' Get Printer Page Information
  103. ' Calc the available space
  104.     LineSpace = PageInfo.tmHeight + PageInfo.tmExternalLeading
  105.     PageSize = GetDeviceCaps(Printer.hdc, VERTRES)
  106.     LinesPerPage = Int(PageSize / (LineSpace - 1)) - 1
  107.     HeaderLine = "                Print Routine Ver 1.0  EJO      Page: "
  108. ' Open the TEXT File to print
  109.     Open DocName For Input As #1
  110.     CurrentLine = 3
  111.     printerACTION.PageNumber.Caption = "Printing Page : 1"
  112.     printerACTION.Refresh
  113.     Printer.Print HeaderLine + "1" + Chr$(13) + Chr$(10)
  114.     Do While Not EOF(1) And DoEvents()
  115. ' Allow the User to ABORT
  116.         code = SetActiveWindow(printerACTION.hdc)
  117.         Line Input #1, PrintLine
  118.         Printer.Print PrintLine
  119.         CurrentLine = CurrentLine + 1  ' increment the Current Line counter
  120.         If CurrentLine > LinesPerPage Then
  121.             CurrentLine = 3
  122.         
  123.             If pABORT = True Then  ' Printing is ABORTED
  124.                 printerACTION.PrinterHEADER.Caption = "Printing has been ABORTED"
  125.                 printerACTION.Refresh
  126.                 delay_it (5)       ' Allow message to be read
  127.                 Exit Do
  128.             Else
  129.                 Printer.NewPage
  130.                 printerACTION.PageNumber.Caption = "Printing Page : " + Str$(Printer.page)
  131.                 printerACTION.Refresh
  132. ' Any Headers Should be Printed Here
  133.                 Printer.Print HeaderLine + LTrim$(Str$(Printer.page)) + Chr$(13) + Chr$(10)
  134.         
  135.             End If
  136.         End If
  137.     Loop
  138. ' Housekeeping for end of Print JOB
  139.     Printer.NewPage
  140.     Printer.EndDoc      ' END of the Printing job
  141.     Close #1
  142. End Sub
  143.